package com.xiaoma.tpo.dao;

import com.xiaoma.tpo.baseDao.BaseDaoImpl;
import com.xiaoma.tpo.baseDao.DefaultRowMapper;
import com.xiaoma.tpo.domain.LiveList;
import com.xiaoma.tpo.utils.Pager;

import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by Owner on 2015/5/15.
 */
@Repository
public class LiveListDao extends BaseDaoImpl<LiveList>{
    public Pager getList(int page,int pageSize){
        String sql = "select id,live_title,live_id,start_time,end_time,status from live_list limit ?,?";
        List<?> list = jdbcTemplate.query(sql, new DefaultRowMapper(LiveList.class, getNameHandler()),(page-1)*pageSize,pageSize);
        String sqlCount ="select count(id) from live_list ";
        int total = jdbcTemplate.queryForInt(sqlCount);
        Pager pager = new Pager();
        pager.setList(list);
        pager.setTotalCount(total);
        return pager;
    }
    
    @SuppressWarnings("unchecked")
    public List<LiveList> getStartLiveList() {
        String sql = "select * from live_list where start_time <= now() and status = 0 limit 1";
        List<?> list = jdbcTemplate.query(sql, new DefaultRowMapper(LiveList.class, getNameHandler()));
        return (List<LiveList>)list;
    }
    
    @SuppressWarnings("unchecked")
    public List<LiveList> getEndLiveList() {
        String sql = "select * from live_list where end_time <= now() and status = 1 limit 1";
        List<?> list = jdbcTemplate.query(sql, new DefaultRowMapper(LiveList.class, getNameHandler()));
        return (List<LiveList>)list;
    }
}
